package crawler;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class HttpNode
{
	private static final int NUMBER_OF_IDENTIFIERS = 5;
	
	public String 	link;
	public String	content;
	public String	planeText;
	public int 		depth;
	public ArrayList<String> identifiers;
	
	HttpNode(String link,int depth)
	{
		
		this.link = link;
		this.depth = depth;
		this.identifiers = new ArrayList<String>();
		
		
	}
	
	public void setContent(String content)
	{
		Pattern REMOVE_TAGS = Pattern.compile("<.+?>");
		Matcher m = REMOVE_TAGS.matcher(content);
		
		this.content = content;
		this.planeText = m.replaceAll("");
		
		/*
		 	HashMap<String , WordCounter> wordsCounter = new HashMap<String, WordCounter>();
		ArrayList<WordCounter> wordsCounterList = new ArrayList<WordCounter>();
	
		 for(String word : content.split(" "))
		{
			if (!wordsCounter.containsKey(word))
			{
				WordCounter wc = new WordCounter(word);
				wordsCounter.put(word,wc);
				wordsCounterList.add(wc);
			}
			
			wordsCounter.get(word).inc();
		}
		
		Collections.sort(wordsCounterList);
		
		
		int size = Math.min(wordsCounterList.size(), NUMBER_OF_IDENTIFIERS);
		for(int i = 0 ; i < size ; ++i)
		{
			WordCounter c = wordsCounterList.get(i);
			identifiers.add(c.word);
		}*/
		
	}

	
	class WordCounter implements Comparable<WordCounter>
	{
		public String word;
		public int counter;
		
		public WordCounter(String word)
		{
			this.word = word;
			counter = 0;
		}
		
		public void inc()
		{
			counter++;
		}
		@Override
		public int compareTo(WordCounter o) {
			Integer mine = new Integer(counter);
			Integer other = new Integer(o.counter);
			
			return mine.compareTo(other);
		}
	}
}